home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / contrib / mysql.pl < prev    next >
Perl Script  |  2006-04-09  |  928b  |  43 lines

  1. #!/opt/lampp/bin/perl
  2. use DBI;
  3.  
  4. print "Content-Type: text/html\n\n";
  5.  
  6. my $dsn="dbi:mysql:phonebook:localhost";
  7. my $dbh=DBI->connect("$dsn","oswald","geheim") or
  8.         die "Kann Datenbank nicht erreichen!";
  9.  
  10. print "<html>";
  11. print "<head>";
  12. print "<title>Perl und MySQL</title>";
  13. print "</head>";
  14. print "<body>";
  15. print "<h1>Perl und MySQL</h1>";
  16. print "<table border=\"1\">";
  17. print "<tr>";
  18. print "<th>Vorname</th>";
  19. print "<th>Nachname</th>";
  20. print "<th>Telefonnummer</th>";
  21. print "</tr>";
  22.  
  23. my $query="SELECT * FROM users";
  24.  
  25. my $prep_sql=$dbh->prepare($query) or  die print "Can't prepare";
  26. $prep_sql->execute() or die print "Can't  execute";
  27.  
  28. while (my @row = $prep_sql->fetchrow_array())
  29. {
  30.     print "<tr>";
  31.     print "<td>".$row[1]."</td>";
  32.     print "<td>".$row[2]."</td>";
  33.     print "<td>".$row[3]."</td>";
  34.     print "</tr>";
  35. }
  36.  
  37. $prep_sql->finish();
  38. $dbh->disconnect();
  39.  
  40. print "</table>";
  41. print "</body>";
  42. print "</html>";
  43.